package com.irdstudio.bhcredit.core.tinycore.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @description:使用SLF4j日志门面框架与遗留代码ILogger进行适配，
 * 				如无特殊情况，请使用SLF4J的LoggerFactory获取logger
 * @date:2019年2月18日 下午5:44:38
 * @author:hengyh
 */
public class Slf4jAdapter implements ILogger {
	private Logger log;
	
	public static Slf4jAdapter wrap(Logger delegate) {
		Slf4jAdapter adapter = new Slf4jAdapter();
		adapter.log = delegate;
		return adapter;
	}
	
	@Override
	public void debug(Object message) {
		log.debug(message.toString());
	}

	@Override
	public void debug(Object message, Throwable t) {
		log.debug(message.toString(), t);
		
	}

	@Override
	public void error(Object message) {
		log.error(message.toString());
	}

	@Override
	public void error(Object message, Throwable t) {
		log.error(message.toString(), t);
	}

	@Override
	public void fatal(Object message) {
		warn("注意：此logger不支持fatal级别，使用error级别，你可以使用更加具体的Logger类型");
		error(message);
	}

	@Override
	public void fatal(Object message, Throwable t) {
		warn("注意：此logger不支持fatal级别，使用error级别，你可以使用更加具体的Logger类型");
		error(message, t);
	}

	@Override
	public void info(Object message) {
		log.info(message.toString());
	}

	@Override
	public void info(Object message, Throwable t) {
		log.info(message.toString(), t);
	}

	@Override
	public void warn(Object message) {
		log.warn(message.toString());
	}

	@Override
	public void warn(Object message, Throwable t) {
		log.warn(message.toString(), t);
	}

	@Override
	public void setName(String categoryName) {
		log = LoggerFactory.getLogger(categoryName);
	}

	@Override
	public ILogger makeSubLogger(String subCategoryName) {
		return wrap(LoggerFactory.getLogger(log.getName() + "-" + subCategoryName));
	}
	

}
